From: Matthieu Gallien Date: Tue, 18 Feb 2025 09:22:50 +0000 (+0100) Subject: ensure correct behavioron Windows for invalid file names X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~2^2~50^2~1 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=0fd16d2d4e1f96cb940f7bbc8b37dd3ce49eed9a;p=nextcloud-desktop.git ensure correct behavioron Windows for invalid file names Signed-off-by: Matthieu Gallien --- diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 1e325d39d..1cd9f6f30 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -292,7 +292,11 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent || excluded == CSYNC_FILE_EXCLUDE_LEADING_AND_TRAILING_SPACE; const auto leadingAndTrailingSpacesFilesAllowed = !_discoveryData->_shouldEnforceWindowsFileNameCompatibility || _discoveryData->_leadingAndTrailingSpacesFilesAllowed.contains(_discoveryData->_localDir + path); +#if defined Q_OS_WINDOWS + if (hasLeadingOrTrailingSpaces && leadingAndTrailingSpacesFilesAllowed) { +#else if (hasLeadingOrTrailingSpaces && (wasSyncedAlready || leadingAndTrailingSpacesFilesAllowed)) { +#endif excluded = CSYNC_NOT_EXCLUDED; } @@ -2282,7 +2286,8 @@ void ProcessDirectoryJob::setupDbPinStateActions(SyncJournalFileRecord &record) void ProcessDirectoryJob::maybeRenameForWindowsCompatibility(const QString &absoluteFileName, CSYNC_EXCLUDE_TYPE excludeReason) { - if (!_discoveryData->_shouldEnforceWindowsFileNameCompatibility) { + const auto leadingAndTrailingSpacesFilesAllowed = !_discoveryData->_shouldEnforceWindowsFileNameCompatibility || _discoveryData->_leadingAndTrailingSpacesFilesAllowed.contains(absoluteFileName); + if (leadingAndTrailingSpacesFilesAllowed) { return; } diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 25e6bf414..515417084 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -688,6 +688,10 @@ void SyncEngine::startSync() _shouldEnforceWindowsFileNameCompatibility = true; _discoveryPhase->_shouldEnforceWindowsFileNameCompatibility = _shouldEnforceWindowsFileNameCompatibility; } +#if defined Q_OS_WINDOWS + _shouldEnforceWindowsFileNameCompatibility = true; + _discoveryPhase->_shouldEnforceWindowsFileNameCompatibility = _shouldEnforceWindowsFileNameCompatibility; +#endif // Check for invalid character in old server version QString invalidFilenamePattern = _account->capabilities().invalidFilenameRegex(); diff --git a/test/testlocaldiscovery.cpp b/test/testlocaldiscovery.cpp index 43a624eaa..87bca0cdf 100644 --- a/test/testlocaldiscovery.cpp +++ b/test/testlocaldiscovery.cpp @@ -418,14 +418,14 @@ private slots: fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, {QStringLiteral("foo"), QStringLiteral("bar"), QStringLiteral("bla"), QStringLiteral("A/foo"), QStringLiteral("A/bar"), QStringLiteral("A/bla")}); QVERIFY(fakeFolder.syncOnce()); -#if defined Q_OS_WINDOWS - QCOMPARE(completeSpy.findItem(fileWithSpaces1)->_status, SyncFileItem::Status::Success); - QCOMPARE(completeSpy.findItem(fileWithSpaces2)->_status, SyncFileItem::Status::Success); - QCOMPARE(completeSpy.findItem(fileWithSpaces3)->_status, SyncFileItem::Status::Success); - QCOMPARE(completeSpy.findItem(fileWithSpaces4)->_status, SyncFileItem::Status::Success); - QCOMPARE(completeSpy.findItem(fileWithSpaces5)->_status, SyncFileItem::Status::Success); - QCOMPARE(completeSpy.findItem(fileWithSpaces6)->_status, SyncFileItem::Status::Success); - QCOMPARE(completeSpy.findItem(extraFileNameWithSpaces)->_status, SyncFileItem::Status::Success); +#if !defined Q_OS_WINDOWS + QCOMPARE(completeSpy.findItem(QStringLiteral("foo"))->_status, SyncFileItem::Status::Success); + QCOMPARE(completeSpy.findItem(QStringLiteral("bar"))->_status, SyncFileItem::Status::Success); + QCOMPARE(completeSpy.findItem(QStringLiteral("bla"))->_status, SyncFileItem::Status::Success); + QCOMPARE(completeSpy.findItem(QStringLiteral("A/foo"))->_status, SyncFileItem::Status::Success); + QCOMPARE(completeSpy.findItem(QStringLiteral("A/bar"))->_status, SyncFileItem::Status::Success); + QCOMPARE(completeSpy.findItem(QStringLiteral("A/bla"))->_status, SyncFileItem::Status::Success); + QCOMPARE(completeSpy.findItem(QStringLiteral("with spaces"))->_status, SyncFileItem::Status::Success); #endif } @@ -605,9 +605,11 @@ private slots: QVERIFY(fakeFolder.syncOnce()); +#if !defined Q_OS_WINDOWS auto expectedState = fakeFolder.currentLocalState(); qDebug() << expectedState; QCOMPARE(fakeFolder.currentRemoteState(), expectedState); +#endif } void testBlockInvalidMtimeSyncRemote()